package com.hhd.cwqs.qs;

import com.hhd.cwqs.entity.CwqsDataSource;
import com.hhd.cwqs.entity.CwqsLog;
import com.hhd.cwqs.entity.CwqsLogDetail;
import com.hhd.cwqs.entity.CwqsUnit;
import com.hhd.cwqs.qs.sql.SingleConnJdbcTemplate;
import com.hhd.cwqs.utils.CommonUtils;
import lombok.Getter;
import lombok.Setter;
import org.jeecg.modules.quartz.entity.QuartzJob;

import java.util.List;

@Getter
@Setter
public class Context {
    private QuartzJob job;

    private CwqsDataSource sourceDataSource;
    private CwqsDataSource targetDataSource;

    private List<String> years = CommonUtils.newList();
    private List<String> monthes = CommonUtils.newList();

    private String accountingSystem;
    private List<CwqsUnit> units = CommonUtils.newList();

    private SingleConnJdbcTemplate sourceSqlTemplate;
    private SingleConnJdbcTemplate targetSqlTemplate;

    CwqsLog log = new CwqsLog();

    public void setJobName(String jobName) {
        log.setJobName(jobName);
    }

    public void addDetailLog(CwqsLogDetail logDetail) {
        log.getDetails().add(logDetail);
    }

    public void createDetailLog(String currentYear, CwqsUnit unit, String message) {
        CwqsLogDetail detail = new CwqsLogDetail();
        detail.setYear(currentYear);
        detail.setUnitId(unit.getId());
        detail.setUnitName(unit.getUnitName());
        detail.setMessage(message);
        addDetailLog(detail);
    }

}
